package com.j180.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.j180.bean.PageBean;
import com.j180.bean.ResultBean;
import com.j180.bean.UserBean;
import com.j180.dao.IUserDao;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.print.Paper;

@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    private IUserDao iUserDao;

    @Override
    public ResultBean showAll(int Curpage,int pageSize) {

       ResultBean resultBean = new ResultBean();
        PageHelper.startPage(Curpage,pageSize);
       //得到分页插件的分页对象
        PageInfo<UserBean> pageInfo = new PageInfo(iUserDao.showAll());

        System.out.println(pageInfo);

        if(pageInfo.getList().size()!=0){
            PageBean<UserBean> pageBean = new PageBean<>();
            pageBean.setCurPage(Curpage);
            pageBean.setPageSize(pageSize);
            pageBean.setTolNum((int)pageInfo.getTotal());
            pageBean.setTolSize(pageInfo.getPages());
            pageBean.setDatas(pageInfo.getList());
            resultBean.setCode(0);
            resultBean.setMsg("操作成功");
            resultBean.setPageBean(pageBean);
        }else{
            resultBean.setCode(1);
            resultBean.setMsg("操作失败");
        }

        return resultBean;
    }

    @Override
    public int addUser(UserBean userBean) {
        return iUserDao.addUser(userBean);
    }
}
